#ifndef __SIGCONTEXT_H__
#define __SIGCONTEXT_H__

#include <signal.h>
#include <ucontext.h>

#include "util/Pool.h"

class CPU;
class Checkpoint;

class SigContext {
  public:
    siginfo_t info;
    ucontext_t context;
    ucontext_t resumeCtx;
    ucontext_t* sigreturnCtx;
    sigset_t savedset;

    int signum;
    
    // overloaded to force use of CALLOC/FREE
    NEW_DELETE_OPERATORS_INLINE_H(SigContext,NoSuper);
    SigContext (int signum, void* extra, size_t extraSize);
    SigContext (siginfo_t* oinfo, ucontext_t* ocontext);
    // the following constructor is to make a simulator-generated singal
    // on memory access related faults such as sigsegv and sigbus.
    SigContext (int signum, VA badAddr);
    ~SigContext ();
    void switchToSigHandling (CPU* runningcpu,
                              Checkpoint* savedcpu,
                              Byte* stack_aligned_end);
    void switchToNormalExec (CPU* runningcpu);
    void invalidateCaches(CPU* runningcpu);
    static long unsigned int getSigIP(ucontext_t* context);
    void updateParameters (CPU* runningcpu);

  private:
    // used for simulator specific extensions to pass extra information
    void*  extra;
    size_t extraSize;
};
#endif // __SIGCONTEXT_H__
